package com.jds.test.bio.p10;

/**
 * https://www.cnblogs.com/silyvin/articles/12055397.html
 * Created by joyce on 2019/11/26.
 */


import java.io.IOException;
import java.net.InetSocketAddress;
import java.net.Socket;
import java.net.UnknownHostException;


public class Client {

    public static final int PORT = 12123;
    public static final int BUFFER_SIZE = 1024;

    public static void main(String []f) throws Exception {
        new Client().client();
    }

    //客户端代码
    public void client() throws Exception{
        final String s2 = "localhost";
        byte[] buffer;
        Socket s = new Socket();
        /**
         * mac 对于Fin_wait2无用，对time_wait同样无用
         * linux 都有用
         */
     //   s.setReuseAddress(true);
        s.bind(new InetSocketAddress(8888));
        s.connect(new InetSocketAddress(s2,PORT));
        int i = s.getInputStream().read(buffer = new byte[BUFFER_SIZE]);
        System.out.println(new String(buffer,0,i));

        /**
         * 程序自然结束，close
         */
    }
}